﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Netcached.Tests
{
    [TestClass]
    public class TestAppendPrepend : BaseTestClass
    {
        [TestMethod]
        public void TestAppend()
        {
            string originalData = "orig";
            string modifyingData = "mod";
            string key = "TestAppendPrepend.TestAppend";

            Client.Set(key, originalData);
            Client.Append(key, modifyingData);

            string fetchedData = Client.Get<string>(key);
            Assert.AreEqual(originalData + modifyingData, fetchedData);
        }

        [TestMethod]
        public void TestPrepend()
        {
            string originalData = "orig";
            string modifyingData = "mod";
            string key = "TestAppendPrepend.TestPrepend";

            Client.Set(key, originalData);
            var result = Client.Prepend(key, modifyingData);

            string fetchedData = Client.Get<string>(key);

            Assert.IsTrue(result);
            Assert.AreEqual(modifyingData + originalData, fetchedData);
        }

        [TestMethod]
        public void TestAppendToNonexistentValue()
        {
            string data = "data";
            string key = "TestAppendPrepend.TestAppendToNonexistentValue";

            var result = Client.Prepend(key, data);

            string fetchedData = Client.Get<string>(key);

            Assert.IsFalse(result);
            Assert.IsNull(fetchedData);
        }
    }
}
